<?php require _APP_PATH_ . '/system/platform/resource/common_inc_header.tpl.php';?>

<span class="layui-breadcrumb">
    <a href="<?php echo url( _MODULE_NAME_ . '/admin.index/index');?>"><?php echo $GLOBALS['config']['module']['name'];?></a>
    <a href="<?php echo url([ _MODULE_NAME_ ,'admin/nav','index']);?>">导航</a>
    <a><cite>添加</cite></a>
</span>

<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this"><a href="<?php echo url([ _MODULE_NAME_ ,'admin.nav','index']);?>">导航</a></li>
    </ul>
</div>

<form class="layui-form" action="<?php echo url([ _MODULE_NAME_ ,'admin/nav','nav_save']);?>" method="post" style="max-width: 900px;margin: 40px auto;">

    <div class="layui-form-item">
        <label class="layui-form-label">名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="请输入导航名称" class="layui-input"
                    lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级导航：</label>
        <div class="layui-input-block">
            <select name="parent_id" lay-verify="required" required >
                <option value="0">一级导航</option>
                <?php foreach($this->rs_nav as $row){ ?>
                    <option value="<?php echo $row['id'];?>"><?php 
                        for($i=2;$i<substr_count($row['parent_path'],',');$i++){ echo '&nbsp; &nbsp; ├ ';}
                        echo $row['name'];?></option>
                <?php } ?>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">位置：</label>
        <div class="layui-input-block">
            <input type="text" name="place" placeholder="请输入显示位置" class="layui-input layui-input-inline" value="" autocomplete="off" />
            <input type="radio" name="place_nav" value="自定义" title="自定义" lay-filter="place_nav" checked>
            <input type="radio" name="place_nav" value="顶部" title="顶部" lay-filter="place_nav">
            <input type="radio" name="place_nav" value="上部" title="上部" lay-filter="place_nav">
            <input type="radio" name="place_nav" value="中部" title="中部" lay-filter="place_nav">
            <input type="radio" name="place_nav" value="下部" title="下部" lay-filter="place_nav">
            <input type="radio" name="place_nav" value="底部" title="底部" lay-filter="place_nav">
            <input type="radio" name="place_nav" value="侧栏" title="侧栏" lay-filter="place_nav">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简介：</label>
        <div class="layui-input-block">
            <input type="text" name="tip" placeholder="请输入导航简介" class="layui-input" lay-verType="tips"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标：</label>
        <div class="layui-input-block">
            <?php echo tpl_file_manager( [ 'nav_img' ] ); ?>
			<br style="clear:both">上传图片尺寸视网站效果自定
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">链接地址：</label>
        <div class="layui-input-block">
            <div class="layui-col-sm10">
                <input type="text" name="url" id="url" placeholder="请输入链接地址" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-col-sm2">
                <button class="layui-btn" type="button" id="choice_url"> 选择链接 </button>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序：</label>
        <div class="layui-input-block">
            <input type="number" name="list_order" placeholder="请输入排序数字" class="layui-input" value="0"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态：</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="启用" checked>
            <input type="radio" name="status" value="0" title="禁用">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="submit" lay-submit >&emsp;提交&emsp;</button>
        </div>
    </div>
</form>

<?php require _APP_PATH_ . '/system/platform/resource/common_inc_footer.tpl.php';?>

<script>

    layui.use(['layer', 'form', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        
        //弹窗
        $(document).on('click','#choice_url',function(){
            layer.open({
                type: 0,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: true,
                btn :'关闭',
                content: '<?php echo $this->nav_url();?>'
            });

            $('.confirm_url').on('click', function(){
                document.getElementById("url").value= $(this).data('url') ;
                layer.close(layer.index);
            });

        })

        // 显示位置
        form.on('radio(place_nav)', function(data){
            var v = data.value;
            if(data.value=='自定义'){
                v = '';
            }
            $('input[name=place]').val( v );
        });
        
    });
    
</script>